Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check collection type before transforming #183

Closed
wants to merge 1 commit into from

Conversation

LarryBarker
Copy link

Improve Error Handling in Forge SDK

Description

This PR aims to enhance the error handling capabilities of the Forge SDK, specifically addressing issues related to unexpected API responses and improving the overall robustness of the SDK.

Changes Proposed

  1. Modified the transformCollection() method in the Forge class to implement more robust error checking.

Motivation and Context

Recent issues with API integrations have highlighted the need for more robust error handling within the Forge SDK. Specifically, unexpected response formats from the API have led to unhandled exceptions, causing disruptions in applications using the SDK.

This PR addresses these issues by implementing best practices for API error handling, as outlined in various resources:

How Has This Been Tested?

  • Manually tested with various API response simulations, including unexpected formats.
  • Integrated and tested in a sample application to ensure compatibility and improved error reporting.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Additional Notes

This PR is part of a larger initiative to improve the overall reliability and user experience of applications integrating with the Forge SDK.

@@ -76,6 +77,12 @@ public function __construct($apiKey = null, ?HttpClient $guzzle = null)
*/
protected function transformCollection($collection, $class, $extraData = [])
{
if (!is_array($collection)) {
throw new Exception(
"Unexpected response format. Expected an array, got " . gettype($response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$response is not a variable in this scope.

@jbrooksuk
Copy link
Member

@LarryBarker I'm closing this as it's been stale for a while, but feel free to implement the feedback from the review and we can look to open this again.

@jbrooksuk jbrooksuk closed this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants